using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Husb.Util;
using Husb.Util.Enum;
using CentralOffice.File.Data;
using CentralOffice.File.BusinessActions;

using FileTable = CentralOffice.File.Data.FileDataSet.FileDataTable;
using FileRow = CentralOffice.File.Data.FileDataSet.FileRow;

namespace CentralOffice.WebClient.Files
{
    public partial class FileView : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                string id = HttpContext.Current.Request.QueryString["id"];
                FileRow file = CentralOffice.File.BusinessActions.Files.GetById(new Guid(id));
                if (file != null)
                {
                    lblName.Text = file.Name;
                    lblSubtitle.Text = file.IsSubtitleNull() ? "" : file.Subtitle;
                    lblFileNumber.Text = file.IsFileNumberNull() ? "" : file.FileNumber;
                    //lblQueryNumber.Text = file.QueryNumber;
                    lblKeywords.Text = file.IsKeywordsNull() ? "" : file.Keywords;
                    lblTheme.Text = file.IsThemeNull() ? "" : file.Theme;
                    lblUrgencyPriority.Text = file.IsUrgencyPriorityNull() ? "" : file.UrgencyPriority;
                    lblPublisher.Text = file.IsPublisherNull() ? "" : file.Publisher;
                    lblSecretLevel.Text = file.IsSecretLevelNull()? "" : file.SecretLevel;
                    lblFileCategory.Text = file.FileCategory;
                    lblRemark.Text = file.IsRemarkNull() ? "" : file.Remark;
                    lblArchivingTime.Text = file.ArchivingTime.ToString();
                    lblArchivedBy.Text = file.ArchivedBy;
                    lblDepositIn.Text = file.IsDepositInNull() ? "" : file.DepositIn;

                    //lblNoticeContent.Text = Server.HtmlDecode(notice.ContentText);

                    //txtAssignedBy.Value = lblAccepter.Text;
                    //txtAssignedByReadOnly.Value = lblAccepter.Text;

                    //SiteUtil.PopulateListBox(ddlStatus, SiteConstants.TaskStatus, false);
                    //ddlStatus.SelectedValue = EnumUtil.GetInt32(SiteConstants.TaskStatus, CategoryDataSourceType.Xml, task.Status).ToString();
                    if (!file.IsAttachmentsNull() && file.Attachments.Length > 0)
                    {
                        string[] attachments = file.Attachments.Split(SiteConstants.CommonSeparatorChar);
                        Repeater2.DataSource = attachments;
                        Repeater2.DataBind();
                    }
                }
            }
        }

        protected void Repeater1_ItemCreated(object sender, RepeaterItemEventArgs e)
        {
            RepeaterItem item = e.Item;
            HyperLink anchor = e.Item.Controls[0] as HyperLink;
            string path = (String)e.Item.DataItem;

            SiteUtil.GenernateDownloadHyperLink(anchor, path);
            //achor.Text = path.Substring(path.LastIndexOf(System.IO.Path.AltDirectorySeparatorChar) + 1);
            //achor.NavigateUrl = SiteUtil.GetDownloadFileName(path);
        }
    }
}
